package com.egao.common.module.workLog.controller;

import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.workLog.entity.AnnualPlan;
import com.egao.common.module.workLog.service.AnnualPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 *  控制器
 *
 * @author shu
 */
@Api(tags = "管理")
@RestController
@RequestMapping("${api}")
public class AnnualPlanController extends BaseController {

    private AnnualPlanService annualPlanService;

    @Autowired
    public AnnualPlanController(AnnualPlanService annualPlanService){
        this.annualPlanService = annualPlanService;
    }

    @PreAuthorize("hasAuthority('annual:plan:list')")
    @ApiOperation("查询列表")
    @GetMapping("/annualPlan/list")
    public PageResult<AnnualPlan> list(HttpServletRequest request) {
        PageParam<AnnualPlan> pageParam = new PageParam<>(request);
        return annualPlanService.list(pageParam);
    }

    @PreAuthorize("hasAuthority('annual:plan:read')")
    @ApiOperation("查询单个")
    @GetMapping("/annualPlan/read/{id}")
    public JsonResult read(@PathVariable("id") Integer id) {
        return annualPlanService.read(id);
    }

    @PreAuthorize("hasAuthority('annual:plan:add')")
    @ApiOperation("添加")
    @PostMapping("/annualPlan/add")
    public JsonResult add(@RequestBody AnnualPlan model) {
    return annualPlanService.add(model);
    }

    @PreAuthorize("hasAuthority('annual:plan:update')")
    @ApiOperation("修改")
    @PostMapping("/annualPlan/update")
    public JsonResult update(@RequestBody AnnualPlan model) {
    return annualPlanService.update(model);
    }

    @PreAuthorize("hasAuthority('annual:plan:delete')")
    @ApiOperation("删除")
    @GetMapping("/annualPlan/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        return annualPlanService.delete(ids);
    }

}